<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>

<!DOCTYPE HTML>
<html>
  <head>
    <title>天安财险</title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
    
    <link href="${ctxStatic }/treeTable/themes/vsStyle/treeTable.min.css" rel="stylesheet" type="text/css" />
	<script src="${ctxStatic }/treeTable/jquery.treeTable.min.js" type="text/javascript"></script>
	<script src="${ctxStatic }/layer/layer.js" type="text/javascript"></script>
  </head>
  
  <body>
  <ul class="nav nav-tabs">
		<li class="active"><a href="javascript:void(0);">机构列表</a></li>
		<li><a href="${ctx}/org/toAdd">机构添加</a></li>
	</ul>

	<table id="treeTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>机构名称</th><th>机构编码</th><th>机构类型</th><th>备注</th><th>操作</th>
			</tr>
		</thead>
		<tbody id="treeTableList">
			<c:forEach items="${items}" var="item">
				<tr id="${item.id }" pId="${item.parent.id ne '1'? item.parent.id:'0'}">
					<td><a href="#">${item.orgname }</a></td>
					<td>${item.orgcode }</td>
					<td>${item.orgtype }</td>
					<td></td>
					<td>
						<a href="${ctx}/org/toEdit?id=${item.id}">修改</a>
						<a href="javascript:void(0);" data-opid="${item.id}" onclick="ms_delete(this)">删除</a>
						<a href="${ctx}/org/toAddChild?id=${item.id}">添加下级机构</a>
					</td>
				</tr>
				
				
			</c:forEach>
		
		</tbody>
	</table>

    <script type="text/javascript">
    	$(function(){
    		$("#treeTable").treeTable({expandLevel : 5});
    	});
    	
    	
    	function ms_delete(obj){
    		var opid = $(obj).data("opid");
    		layer.confirm('要删除该机构及所有子机构项吗？', {
       		    btn: ['确认','取消'], //按钮
       			title:'温馨提示'
       		}, function(){
       			$.ajax({
       				dataType : "json",
       				type : "POST",
   					url : "${ctx}/org/delete",
   					data : {id : opid},
   					success : function(data){
   						if(data.result == "1"){
   							location.reload();
   						}
   					},
   					error : function(){
   						layer.alert("删除失败");
   					}
   				});
       		}, function(){
       		});
    	}
    </script>
    
  </body>
</html>
